package com.global.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.hibernate.annotations.Type;

/**
 * The persistent class for the ZLY_ST_BSC_RPCA database table.
 * <br/>从SystemType中从独立出来
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate=true)
@Table(name="ZLY_ST_BSC_RPCA")
@SequenceGenerator(name="ZLY_ST_BSC_RPCA_ID_GENERATOR", sequenceName="ZLY_ST_BSC_RPCA_ID_SEQ", initialValue=100, allocationSize=1)
@NamedQueries({
        @NamedQuery(
                name = "findReportCategotyByName",
                query = "select r from ReportCategory r where upper(r.name) = :uniqueName "
        )   
})
public class ReportCategory extends BaseObject implements Serializable {

	private static final long serialVersionUID = 3196628841612950504L;
	
	private Long id;
	private String name;
	private String description;	
	private boolean status;

    /**
     * 定义操作人、操作时间
     */
    private Who who;

    public ReportCategory() { }
    
    public ReportCategory(String name, String description) {
    	this.name = name;
    	this.description = description;
    }
    
	/**
	 * {@inheritDoc}
	 */
	@Id	
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ZLY_ST_BSC_RPCA_ID_GENERATOR")
	@SearchableId
	public Long getId() {
		return this.id;
	}
	/**
	 * {@inheritDoc}
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 返回参数名称
	 * @return String
	 */
	@Column(nullable=false, unique=true)
	@SearchableProperty
	public String getName() {
		return this.name;
	}
	/**
	 * 设置参数名称，要符合用户名的命名规则
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(nullable=false)
	@SearchableProperty
	public String getDescription() {
		return this.description;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * 返回参数的有效状态
	 * @return boolean，true表示有效
	 */
	@Column(nullable=false, length=1)
	@Type(type="yes_no")
	public boolean getStatus() {
		return this.status;
	}
	/**
	 * 设置参数类型是否有效
	 * @param status
	 */
	public void setStatus(boolean status) {
		this.status = status;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public Who getWho() {
		return who;
	}
	/**
     * {@inheritDoc}
     */
	@Override
	public void setWho(Who who) {
		this.who = who;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
        .append("name", this.name)
        .append("description", this.description)
        .append("status", this.status);

        return sb.toString();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		
		return result;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		
		ReportCategory other = (ReportCategory) obj;
		
		if (id != other.id){
			if (name == null) {
				if (other.name != null)
					return false;
			} else if (!name.equalsIgnoreCase(other.name)){
				return false;
			}
		}
		
		return true;
	}
}
